<template>
  <div id="articleList">
    <el-input size="small" @keyup.enter.native="searchHandle" style="width: 300px" v-model="keywords" placeholder="搜索文章标题或发布者名称"></el-input>
    <el-button @click="searchHandle()" style="margin-left: 10px" type="primary" icon="el-icon-search" size="small">搜索</el-button>
    <div style="display: inline-block;margin-left: 20px;font-size:14px;">
      筛选：
      <el-radio v-model="hasAuth" label='0' @change="searchHandle">未审核</el-radio>
      <el-radio v-model="hasAuth" label='2' @change="searchHandle">未通过</el-radio>
    </div>
    <el-table
        height="536"
        :data="articleList"
        v-loading="loading"
        element-loading-text="拼命加载中"
        style="width: 99.5%">
      <el-table-column
          label="序号"
          align="center"
          type="index"
          :index="indexMethod">
      </el-table-column>
      <el-table-column
          label="文章标题"
          prop="articleTitle"
          align="center"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="发布者"
          prop="userName"
          align="center"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="文章类别"
          align="center"
          prop="articleType"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="文章内容"
          prop="articleContent"
          align="center"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="评论数"
          align="center"
          prop="commentNumber"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="发布时间"
          prop="createTime"
          sortable
          align="center"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="操作"
          align="center"
          width="200%">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="light" content="详细信息" placement="top" >
            <el-button @click="detailInfo(scope.row)" size="mini" type="success" class="iconfont icon-xiangqing"></el-button>
          </el-tooltip>
          <el-tooltip class="item" v-show="hasAuth!='2'" effect="light" content="审核通过" placement="top" >
            <el-button @click="aduit(scope.row.articleId,scope.row.articleTitle,'pass')" size="mini" class="iconfont icon-shenhetongguo" type="success"></el-button>
          </el-tooltip>
          <el-tooltip class="item" v-show="hasAuth!='2'" effect="light" content="审核不通过" placement="top" >
            <el-button @click="aduit(scope.row.articleId,scope.row.articleTitle,'noPass')" size="mini" class="iconfont icon-shenhebutongguo" type="danger"></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="total,prev, pager, next"
        :total="total"
        align="center"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        :hide-on-single-page="value"
        style="padding-top: 15px"
    >
    </el-pagination>
    <el-dialog title="文章浏览" center :visible.sync="detailInfoVisible" width="60%" :close-on-click-modal="false"
               :lock-scroll="false">
      <el-descriptions  direction="vertical" :column="2" size="small" border>
        <el-descriptions-item>
          <template slot="label">
            文章标题
          </template>
          {{ article.articleTitle }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            发布者
          </template>
          {{ article.userName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            文章内容
          </template>
          <div style="white-space: pre-line">
            {{article.articleContent}}
          </div>
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import {auditArticle, getArticleList,} from "../../network/admin";

export default {
  name: "ArticleAudit",
  data(){
    return{
      articleList:[],
      article:{},
      loading:false,
      keywords:'',
      value:false,
      currentPage:1,
      total:1,
      pageSize:9,
      detailInfoVisible:false,
      hasAuth:'0'
    }
  },

  created() {
    this.handleCurrentChange(this.currentPage);
  },
  methods:{
    handleCurrentChange(currentPage){
      getArticleList(this.keywords,currentPage,this.pageSize,parseInt(this.hasAuth)).then(res=>{
        this.loading=false;
        this.total=res.data.data.total;
        this.articleList=res.data.data.list;
        this.currentPage=currentPage;
      })
    },
    searchHandle(){
      this.currentPage = 1;
      this.handleCurrentChange(this.currentPage)
    },
    aduit(articleId,articleTitle,res){
      auditArticle(articleId,res).then(res=>{
        if(res.data.data=="pass"){
          this.$message.success(articleTitle+"审核通过");
        }else if(res.data.data=="noPass"){
          this.$message.warning(articleTitle+"审核不通过");
        }
        this.handleCurrentChange(this.currentPage);
      })
    },
    indexMethod(index) {
      return (this.currentPage-1)*this.pageSize+1 + index;
    },
    detailInfo(article){
      this.detailInfoVisible = true;
      this.article = article;
    }
  }
}
</script>

<style scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label{
  min-width: 130px;
  height:50px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-left: 50px;
  margin-bottom: 0;
  width: 40%;
}
.el-form-item__content{
  height:50px;
}
</style>